package com.bdqn.service.impl;

import com.bdqn.dao.UserDao;
import com.bdqn.dao.UserDaoFatory;
import com.bdqn.entity.User;
import com.bdqn.service.UserService;

public class UserServiceImpl implements UserService {
   /* //实例化所依赖的UserDao对象
    private UserDao dao = new UserDaoImpl();
    public void save(User user) {
        //调用UserDao的方法保存用户信息
        dao.save(user);
    }*/

    //通过工厂获取所依赖的UserDao对象
    private UserDao dao = UserDaoFatory.getInstance();
    /**
     * 保存用户信息
     */
    public void save(User user){
        //调用UserDao的方法保存用户信息
        dao.save(user);
    }

    /**
     * 声明接口类型的引用，和具体实现类解耦合
     */
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
